package com.springboot.demo.Controller;
import com.springboot.demo.Service.UserService;
import com.springboot.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class UserContoller {

    @Autowired
    private UserService service;

    @RequestMapping("/get")
    public User getByID(Integer id){
        User user= (User) service.getById(id);
        return  user;
    }

    @RequestMapping("/listUser")
    List<User> listUser(){
        return service.listUser();
    }

@RequestMapping("/addUser")
   public void addUser(User user){
        service.addUser(user);
    }

    @RequestMapping("/delUser")
    public String delUser(int id){
       int result= service.delUser(id);
        if(result>=0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping("/updateUser")
    public String updateUser(User user) {
       int result= service.updateUser(user);
        if(result>=0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
}
